﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JTicket.DAL
{
    public class H_Return
    {
        public static bool Exist(string BarCode, string TitleCode)
        {
            var x = DbHelper.GetAccess.H_Returns.FirstOrDefault(a => a.stitlecode == TitleCode && a.BarCode == BarCode);
            if (x != null)
                return true;
            else
                return false;

        }

        public static bool GetStatus(string BarCode, string TitleCode)
        {
            if (Exist(BarCode, TitleCode))
            {
                var x = DbHelper.GetAccess.H_Returns.First(
                    a => a.stitlecode == TitleCode
                    && a.BarCode == BarCode);
                if (x.Status == 2)
                    return true;
                else
                    return false;
            }
            return false; 
        }
        public static List<Model.H_Return> GetList(string OperCode)
        {
            var x = from a in DbHelper.GetAccess.H_Returns
                    where a.OperCode == OperCode
                    orderby a.SaleDate, a.SaleTime descending
                    select a;

            if (x.Count() > 0)
                return x.ToList();
            else
                return new List<Model.H_Return>(0);

        }

        public static List<Model.H_Return> GetListT(string ThCode, int status)
        {
            var x = from a in DbHelper.GetAccess.H_Returns
                    where a.ThCode==ThCode && a.Status==status
                    orderby a.OperCode, a.SaleDate, a.SaleTime descending
                    select a; 
            if (x.Count() > 0)
                return x.ToList();
            else
                return new List<Model.H_Return>(0);

        }
        public static List<Model.H_Return> GetLists(int status)
        {
            var x = from a in DbHelper.GetAccess.H_Returns
                    where a.Status == status
                    orderby a.OperCode, a.SaleDate, a.SaleTime descending
                    select a;
            if (x.Count() > 0)
                return x.ToList();
            else
                return new List<Model.H_Return>(0);

        }
    }
}